<?php

class Core_Component_System_Model_Component extends Soul_Model_Entity_Base{

	protected $tableName = '{t}system_component';
    
    public function validate() {
        if ($this->isNew()) {
        	if($this->checkExists(array('code'=>$this->getCode()))){
        		throw new Core_Component_System_Exception(Core_Component_System_Exception::COMPONENT_EXISTED);
        	}
        }
        return parent::validate();
    }
    
    public function update() {
        throw new Exception('Not support this method');
    }
    
    public function updateBatch(array $ids) {
        throw new Exception('Not support this method');
    }
    
    public function deleteBatch(array $ids) {
        throw new Exception('Not support this method');
    }
    
    protected function afterInsert(){
        if($this->getIsCreateDirectory()){
            App::getBusiness('system/component')->createDirectory($this);
        }
        parent::afterInsert();
    }
    
    protected function beforeDelete(){
        App::getBusiness('system/component')->uninstall($this);        
        parent::beforeDelete();
    }

    protected function initializeProperties() {
        $this->createProperty('id', 'integer', TRUE, TRUE);
        $this->createProperty('code', 'string')
                ->setLabel('system.label.code');
        $this->createProperty('name', 'string')
                ->setLabel('system.label.name');
        $this->createProperty('author', 'string')
                ->setLabel('system.label.author');
        $this->createProperty('version', 'string')
                ->setLabel('system.label.version');
        $this->createProperty('website', 'string')
                ->setLabel('system.label.website');
        $this->createProperty('email', 'string')
                ->setLabel('system.label.email');
        $this->createProperty('core', 'boolean');
        $this->createProperty('status', 'string')
                ->setDefaultValue(CONSTANT_STATUS_ENABLED)
                ->setInputType(NULL);
        $this->createProperty('description', 'string')
                ->setLabel('system.label.description');
        $this->createProperty('created_time', 'timestamp')
                ->setLabel('system.label.created_time')
                ->setInputType(NULL)
                ->setUpdateable(FALSE);
    }    
}
